//插件容器是一个用来执行插件的容器
async function createPluginContainer({plugins}) {
  class PluginContext {}

  const container = {
    // resolveId是一个根据标记符号算路径的方法
    // import vue from 'vue' => vue 在硬盘上对应的路径
    async resolveId(id, importer) {
      const ctx = new PluginContext();
      for (const plugin of plugins){
        if(!plugin.resolveId) continue;
        const result = await plugin.resolveId.call(ctx,id,importer);
        if(result) return result;
      }
      return {id};
    }
  };

  return container;
}

exports.createPluginContainer = createPluginContainer;
